﻿using System;
using System.Text;
using System.Web.UI;
using Spring.Context;
using Spring.Context.Support;
using GONES.Tools.Common;
using GONES.IBLL;
using System.Collections.Generic;
using System.Xml;
using System.Web;
using System.Data;


public partial class Console_Login : Page
{
    public string ErrorMessage { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            if (!string.IsNullOrEmpty(Tools.GetCookie("loginname")))
            {

                txtUserName.Text =
                    Encoding.UTF8.GetString(Encoding.Default.GetBytes(Tools.GetCookie("loginname")));
                //cbSavePass.Checked = true;
            }
        }
    }

    protected void ProgramLogin(string loginName, string loginPass)
    {
        IApplicationContext appContext = ContextRegistry.GetContext();
        var userInfoManager = appContext.GetObject("S_UsersManager") as IS_UsersManager;
     
        LoginInfo loginInfo = userInfoManager.Login(loginName, loginPass);
        if (loginInfo.UserId != null)
        {
            Session["LoginInfo"] = loginInfo;
            Response.Redirect("Default.aspx");
        }
        else
        {
            ErrorMessage = userInfoManager.ErrMsg;
        }
    }
    protected void imgLogin_Click(object sender, ImageClickEventArgs e)
    {
        ProgramLogin(txtUserName.Text.Trim(), txtPassword.Text.Trim());
    }

    public string GetNotices()
    {
        DataSet myds = new DataSet();
        myds.ReadXml(Server.MapPath("~/Configs/SysNotice.xml"));
        string notices = "";
        for (int i = 0; i < myds.Tables[0].Rows.Count; i++)
        {
            notices += string.Format("<p>{0}</p>", myds.Tables[0].Rows[i]["notice_Text"].ToString());
        }
        return notices;
    }
}